﻿using System.Collections.Concurrent;
using System.Runtime.CompilerServices;

namespace HappyDog
{
    public static class Extensions
    {
        public static void SetDicValue(this  ConcurrentDictionary<string, string> dic, string dogname, string value)
        {
            dic.AddOrUpdate(dogname, a =>
            {
                return value;
            }, (a, b) =>
            {
                return value;
            });
        }
        public static string GetDicValue(this ConcurrentDictionary<string, string> dic, string dogname)
        {
            if (dic.TryGetValue(dogname, out string val))
            {
                return val;
            }
            else
            {
                return "-";
            }
        }
        public static string FormatToTime(this string dt)
        {
            if (DateTime.TryParse(dt, out DateTime dtt))
            {
                return dtt.Hour + ":" + dtt.Minute + ":" + dtt.Second;
            }
            else
            {
                return "";
            }
        }
        public static string FormatToTime(this DateTime dtt)
        {
            return dtt.Hour + ":" + dtt.Minute + ":" + dtt.Second;
        }
    }
}
